@inject ToastService ToastService

<Buttons HasAddons>
    <Button Color="Color.Danger" @onclick="() => t1.ClearCheckedRows()">Clear</Button>
    <Button Color="Color.Info" @onclick="() => t1.ToggleCheckedRows()">Toggle</Button>
    <Button Color="Color.Success" @onclick="() => showChecked()">Show Checked Count</Button>
</Buttons>

<DataTable @ref="t1" Data="data" TdClass="@B.TextCentered" ThClass="@B.TextCentered" TItem="Person"
            IsNarrow IsHoverable IsBordered IsStriped IsFullwidth>
    <DataTableColumn Width="100px" TItem="Person" IsCheckBox/>
    <DataTableColumn Label="Id" Prop="Id"/>
    <DataTableColumn Label="名称" Prop="Name"/>
    <DataTableColumn Label="年龄" Prop="Age"/>
    <DataTableColumn Label="性别" Prop="Gender"/>
    <DataTableColumn Label="生日" Format="yyyy-MM-dd" Prop="Birthday"/>
</DataTable>
<Pagination TotalCount="@totalCount" PageIndex="pageIndex" PageSize="pageSize" OnPageChange="onPage"
            NextText="下一页" PrevText="上一页" IsCentered IsSmall/>

@code{
    int pageIndex = 1;
    int pageSize = 2;
    int totalCount = 0;
    IEnumerable<Person> data;
    DataTable<Person> t1;
    void onPage(int page)
    {
        pageIndex = page;
        search();
    }
    
    void search()
    {
        data=Person.GetPageData("",pageIndex, pageSize, out int total);
        totalCount = total;
    }
    protected override void OnInitialized()
    {
        base.OnInitialized();
        search();
    }
    
    //显示选中行
    async Task showChecked()
    {
        var rows = t1.GetCheckedRows();
        await ToastService.Show(new ToastOptions(){Message ="选中行数："+ rows.Count});
    }
}